<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<script type="text/javascript">
		var arr = [12,2,190,64,56,63,29];
		// 如果有n个数字，则需要n-1轮
		// 每一轮需要比较n-i次，i代表第几轮
		for( var i=1;i<arr.length;i++ ){// 外层循环控制轮数
			for( var j=0;j<arr.length-i;j++ ){// 内层循环控制每一轮的次数
				if( arr[j]>arr[j+1] ){
					var temp = arr[j];
					arr[j] = arr[j+1];
					arr[j+1] = temp;
				}
			}
		}

		// 二分法
		var arr = [2, 12, 13, 29, 56, 63, 64, 99, 130, 165, 167, 189, 190];
		function fn(arr,num){
			var min = 0;// 290
			var max = arr.length-1;
			var mid = parseInt((min+max)/2);

			while( min<=max ){
				if( arr[mid] == num ){
					return mid;
				}else if( arr[mid] > num ){
					max = mid-1;
					mid = parseInt((min+max)/2);
				}else if(arr[mid] < num){
					min = mid+1;
					mid = parseInt((min+max)/2);
				}
			}
			return -1;
		}

	</script>
</head>
<body>
	function fn(){
			alert(1);
		}
	<pre>
		function fn(){
			alert(1);
		}
	</pre>
</body>
</html>